package com.igeekhome.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeekhome.biz.IVisitorInfoService;
import com.igeekhome.pojo.VisitorInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//import javax.jws.WebParam;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 视图统计 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-03-16
 */
@Controller
@RequestMapping("/visitorInfo")
public class VisitorInfoController {
    @Autowired
    private IVisitorInfoService iVisitorInfoService;
    @RequestMapping("/visitor")
    public String visitor(Model m, @RequestParam("value") String value, @RequestParam("current") Integer current, @RequestParam("size") Integer size){
        QueryWrapper<VisitorInfo> qw=new QueryWrapper<>();
        qw.orderByDesc("visittime");
        qw.like("visitorname", value);
//        ArrayList<VisitorInfo> arrayList= new ArrayList<>();
//        arrayList= (ArrayList<VisitorInfo>) iVisitorInfoService.list(qw);

        IPage<VisitorInfo> page=new Page<>(current,size);


        IPage<VisitorInfo> page1 = this.iVisitorInfoService.page(page,qw);
        List<VisitorInfo> list = page1.getRecords();
        long pagesCount = page1.getPages();
        m.addAttribute("pagesCount",pagesCount);
//        initcustomerservice(m,current,size);
        m.addAttribute("visitor_list",list);//将arrayList隐藏到visitor_list中
//        m.addAttribute("fklb","访客列表");
        m.addAttribute("fk","访客列表");
        return "forward:/tables";
    }

    public void initcustomerservice(Model model, Integer current, Integer size)
    {

        IPage<VisitorInfo> page=new Page<>(current,size);
        IPage<VisitorInfo> page1 = this.iVisitorInfoService.page(page);

        List<VisitorInfo> list = page1.getRecords();
        long pagesCount = page1.getPages();


//        model.addAttribute("list",list);
        model.addAttribute("pagesCount",pagesCount);
//        model.addAttribute("main","客服管理主页");

    }

}

